<?php
// 提交报修后台
header("content-type:text/html;charset=utf-8");
include_once("conn.php");

//设置默认时区
date_default_timezone_set('PRC');
$repairID = date('YmdHis', time()) . mt_rand(1000, 9999);
$now_date = date('Y-m-d H:i:s', time());

//获取用户提交的信息
$u_id = $_POST['uid'];
$u_name = $_POST['u_name'];
$u_phone = $_POST['u_phone'];
$fault_area = $_POST['fault_area'];
$fullAddress = $_POST['fullAddress'];
$fault_type = $_POST['fault_type'];
$fault_reason = $_POST['fault_reason'];
$depicted = $_POST['depicted'];
$fault_img = $_FILES['fault_img'];

$path = '../../img/user_upload/';
$FileName = $fault_img['name'];
$a = explode('.', $FileName);
$b = end($a); //获取文件后缀名
$FileName = $repairID . '.' . $b;
$FilePath = $path . $FileName;
if(move_uploaded_file($fault_img['tmp_name'], $FilePath)){
    $sql = "insert into tb_fixinfo_request (u_id, fix_id, fix_name, fix_phone, fix_area, fix_address, fix_type, fix_reason, fix_depicted, fix_img, fix_sendtime)
    values('".$u_id."', '".$repairID."','".$u_name."','".$u_phone."','".$fault_area."','".$fullAddress."','".$fault_type."','".$fault_reason."','".$depicted."','".$FileName."','".$now_date."')";
    if(mysqli_query($conn_DB,$sql)){
        echo "<script>alert('您已提交一条申请！');location='../u-follow-fixinfo.php';</script>";
    }else{
        // echo "<script>alert('提交失败！请重试！');history.go(-1);</script>";
        echo $sql;
    }
}
